package geppetto.phraseHMM.phraseExtraction.extractedphrase.data;

import geppetto.phraseHMM.WordTrie;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePair;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairData;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairDataCalc;
import geppetto.phraseHMM.phraseExtraction.extractedphrase.SentenceInfo;
import geppetto.reordering.graph.PhraseDependencyTree;
import geppetto.reordering.graph.ReorderingGraph;
import geppetto.reordering.graph.scorers.NoDiscontinuousScorer;

public class ReorderingGraphDataCalc  implements ExtractedPhrasePairDataCalc{
	
	WordTrie sourceTrie;
	WordTrie targetTrie;
	
	public ReorderingGraphDataCalc(WordTrie sourceTrie, WordTrie targetTrie) {
		super();
		this.sourceTrie = sourceTrie;
		this.targetTrie = targetTrie;
	}

	@Override
	public ExtractedPhrasePairData calcData(ExtractedPhrasePair epp) {
		SentenceInfo info = epp.getSentenceInfo();
		if(info.getCustomInfo("sub-phrase-graph") == null){
			info.setCustomInfo("sub-phrase-graph", getGraph(info));			
		}
		return PhraseDependencyTree.generateGraphDataForPhrase(epp, sourceTrie, targetTrie, epp.getSentenceInfo().getExtractedPhrasePairTable());
	}

	@Override
	public ExtractedPhrasePairData loadFromString(String s) {
		return ReorderingGraphData.parseString(s);
	}

	public ReorderingGraph getGraph(SentenceInfo senInfo){
		ReorderingGraph graph = new ReorderingGraph(senInfo);
		//graph.setScorer(new NoDiscontinuousScorer());
		//graph.generateWeightedGraphAllPaths();
		return graph;
	}
	
}
